﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Shop : MonoBehaviour
{
    public ToolbarUI toolbarUI;
    public GameObject shop_window;

    public Transform current_position;

    public GameObject item_0;
    public GameObject item_1;
    public GameObject item_2;
    public GameObject item_3;
    public void Open_shop()
    {
        shop_window.SetActive(true);
    }
    public void Close_shop()
    {
        shop_window.SetActive(false);
    }

    public void Buy_item(int price)
    {
        if(GameObject.Find("游戏系统").GetComponent<GoldCoin>().coin_num >= price)
        {
            GameObject.Find("游戏系统").GetComponent<GoldCoin>().coin_num -= price;
            if(price == 10)
            {
                Instantiate(item_0, current_position.position, Quaternion.identity);
            }
            if (price == 50)
            {
                Instantiate(item_1, current_position.position, Quaternion.identity);
            }
            if (price == 100)
            {
                Instantiate(item_2, current_position.position, Quaternion.identity);
            }
            if (price == 150)
            {
                Instantiate(item_3, current_position.position, Quaternion.identity);
            }

        }
    }
    public void Sell_Seed_Carrotr()
    {
        if (toolbarUI.GetSelectSlotUI().GetData().item != null)
        {
            if (toolbarUI.GetSelectSlotUI().GetData().item.type == ItemType.Seed_Carrot)//胡萝卜种子
            {
                if(toolbarUI.GetSelectSlotUI().GetData().count > 0)
                {
                    toolbarUI.GetSelectSlotUI().GetData().Reduce();
                    GameObject.Find("游戏系统").GetComponent<GoldCoin>().coin_num += 10;
                }
            }
        }
    }
    public void Sell_Seed_Tomato()
    {
        if (toolbarUI.GetSelectSlotUI().GetData().item != null)
        {
            if (toolbarUI.GetSelectSlotUI().GetData().item.type == ItemType.Seed_Tomato)//胡萝卜种子
            {
                if (toolbarUI.GetSelectSlotUI().GetData().count > 0)
                {
                    toolbarUI.GetSelectSlotUI().GetData().Reduce();
                    GameObject.Find("游戏系统").GetComponent<GoldCoin>().coin_num += 10;
                }
            }
        }
    }
}
